home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / rrsql60.000 / rr_sql60.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  26KB  |  716 lines

  1. { Second attempt at a Delphi Visual component for R&R runtime }
  2. { You are free to distribute and use this file as you wish with this header }
  3. { Please email any comments/enhancements to cbrooksbank@msn.com }
  4.  
  5. { Needs R&R Report Writer - SQL Edition V6.0 - Concentric Data Systems, Inc.}
  6. { Author Chris Brooksbank (cbrooksbank@msn.com) }
  7. { Written : June 1995 }
  8. { Needs rrsqlint }
  9.  
  10. { October 1995 changes :
  11. Changed class name from TReportRR to TRRSQL60
  12.   ( needed because some propertys changed String to enumarated lists )
  13.  
  14. GPF bug on editing any stringlist property (e.g. sortfields) fixed
  15.  
  16. function prototypes in interface unit defined as far
  17.  
  18. resource protection on execute method improved
  19.  
  20. execute method now returns TRUE/FALSE for success/failure
  21.  
  22. join information for reports now loaded ( JoinTablenames and JoinAliasNames )
  23.  
  24. drop down lists for several propertys e.g. report destination
  25.  
  26. askprinter property for interactive printer selection by user
  27.  
  28. askreport property for interactive report selection by user
  29.  
  30. askdatasource property for interactive datasource selection by user
  31.  
  32. asktable property for interactive table selection by user
  33.  
  34. edited changes to sort/group/joins is now passed to report in execute
  35.  
  36. run method added ( does same as execute )
  37.  
  38. user paramaters added and passed to report on execute
  39.  
  40. lasterrorcode and lasterrormessage property added
  41.  
  42. active property added to allow report running at design time
  43.  
  44. added Database property
  45.  
  46. execute method now uses anything setup in replaces property
  47.  
  48. added where property for Auto-SQL reports
  49. }
  50.  
  51. unit RR_SQL60;
  52.  
  53. interface
  54.  
  55. uses
  56.   SysUtils,WinTypes,WinProcs,Messages,Classes,Graphics,Controls,Forms,
  57.   Dialogs,rrsqlint,DsgnIntf;
  58.  
  59. type
  60.   TrrFilterUsage = (rrfuSaved,rrfuNone,rrfuComponent,rrfuInteractive);
  61.   TrrDest = (rrdDisplay,rrdTextFile,rrdPrinter,rrdWorksheet,rrdXBase,
  62.              rrdInteractive);
  63.   TrrExportDest = (rredDisplay,rredFile,rredPrinter);
  64.   TrrwsBorderStyle = (rrwsNone,rrwsFixedSingle,rrwsSizable,rrwsFixedDouble);
  65.  
  66.   TRRSQL60 = class(TComponent)
  67.   private
  68.     { Private declarations }
  69.      fActive:Boolean;
  70.      fAskPrinter:Boolean;
  71.      fAskReport:Boolean;
  72.      fAskDataSource:Boolean;
  73.      fAskTable:Boolean;
  74.      fAuthor:String;
  75.      fAppName:String;
  76.      fBeginPage: Longint;
  77.      fCopies: Longint;
  78.      fDatabasename: String;
  79.      fDataDir    : String;
  80.      fDataSource: String;
  81.      fDisplayErrors: Boolean;
  82.      fDisplayStatus: Boolean;
  83.      fEndPage: LongInt;
  84.      fErrorCode: String;
  85.      fErrorMessage: String;
  86.      fExportDest: TrrExportDest;
  87.      fFields: TStrings;
  88.      fFilter: String;
  89.      fFilterUsage: TrrFilterUsage;
  90.      fGroupFields: TStrings;
  91.      fImageDir   : String;
  92.      fJoinTablenames: TStrings;
  93.      fJoinAliasNames: TStrings;
  94.      fLibName: String;
  95.      fMasterTableName: String;
  96.      fMemoName: String;
  97.      fOutputDest: TRRDest;
  98.      fOutputFile: String;
  99.      fPassword: String;
  100.      fPreventEscape: Boolean;
  101.      fPrinterName: String;
  102.      fPrinterPort: String;
  103.      fReplaces: TStrings;
  104.      fRepName:String;
  105.      fReportPick: Boolean;
  106.      fSortFields: TStrings;
  107.      fStatusEveryPage: Boolean;
  108.      fSuppressTitle: Boolean;
  109.      fTestPattern: Boolean;
  110.      fUserName: String;
  111.      fUserParamsNames: TStrings;
  112.      fUserParamsValues: TStrings;
  113.      fVersion: String;
  114.      fWait: Boolean;
  115.      fWhere:String;
  116.      fWinBorderStyle: TrrwsBorderStyle;
  117.      fWinControlBox: Boolean;
  118.      fWinHeight: Integer;
  119.      fWinLeft:Integer;
  120.      fWinMaxButton: Boolean;
  121.      fWinMinButton: Boolean;
  122.      fWinParentHandle: Integer;
  123.      fWinTitle: String;
  124.      fWinTop: Integer;
  125.      fWinWidth:Integer;
  126.      procedure SetRepName(NewRepName: String);
  127.      procedure SetLibName(NewLibName:String);
  128.      procedure LoadReportInfo;
  129.      procedure LoadFields(hReport:Integer);
  130.      procedure LoadGroupFields(hReport:Integer);
  131.      procedure LoadSortFields(hReport:Integer);
  132.      procedure LoadJoins(hReport:Integer);
  133.      procedure LoadUserParams(hReport:Integer);
  134.   protected
  135.     { Protected declarations }
  136.   public
  137.     { Public declarations }
  138.     constructor Create(Aowner:TComponent); override;
  139.     destructor Free;
  140.     function execute:Boolean;
  141.     function run:Boolean;
  142.     procedure setfFields(Value:Tstrings);
  143.     procedure setfGroupFields(Value:Tstrings);
  144.     procedure setfJoinTableNames(Value:Tstrings);
  145.     procedure setfJoinAliasNames(Value:Tstrings);
  146.     procedure setfReplaces(Value:Tstrings);
  147.     procedure setfSortFields(Value:Tstrings);
  148.     procedure setfUserParamsNames(Value:Tstrings);
  149.     procedure setfUserParamsValues(Value:Tstrings);
  150.     procedure setfActive(Value:Boolean);
  151.     procedure setfAuthor(Value:String);
  152.     procedure savereplaces(hReport:Integer);
  153.     procedure loadreplaces(hReport:Integer);
  154.   published
  155.     { Published declarations }
  156.     property Active: Boolean read fActive write SetfActive;
  157.     property AppName: String read fAppName write fAppName;
  158.     property AskPrinter:Boolean read fAskPrinter write fAskPrinter;
  159.     property AskReport:Boolean read fAskReport write fAskReport;
  160.     property AskDataSource:Boolean read fAskDataSource write fAskDataSource;
  161.     property AskTable:Boolean read fAskTable write fAskTable;
  162.     property Author: String read fAuthor write setfAuthor;
  163.     property BeginPage: Longint read fBeginPage write fBeginPage default 1;
  164.     property Copies: Longint read fCopies write fCopies default 1;
  165.     property Databasename:String read fDatabasename write fDatabasename;
  166.     property DataSource: String read fDataSource write fDataSource;
  167.     property DisplayErrors: Boolean read fDisplayErrors write fDisplayErrors;
  168.     property DisplayStatus: Boolean read fDisplayStatus write fDisplayStatus;
  169.     property EndPage: Longint read fEndPage write fEndPage default 999999;
  170.     property ErrorCode: String read fErrorcode write fErrorcode;
  171.     property ErrorMessage: String read fErrorMessage write fErrorMessage;
  172.     property ExportDest: TrrExportDest read fExportDest write fExportDest;
  173.     property Fields: TStrings read fFields write setfFields;
  174.     property Filter: String read fFilter write fFilter;
  175.     property FilterUsage: TrrFilterUsage read fFilterUsage write fFilterUsage;
  176.     property GroupFields: TStrings read fGroupFields write setfGroupFields;
  177.     property JoinTableNames: TStrings read fJoinTableNames
  178.                                       write setfJoinTableNames;
  179.     property JoinAliasNames: TStrings read fJoinAliasNames
  180.                                       write setfJoinAliasNames;
  181.     property MasterTableName: String read fMasterTableName write fMasterTableName;
  182.     property MemoName: String read fMemoName write fMemoName;
  183.     property OutputDest: TrrDest read fOutputDest write fOutputDest
  184.                                  default rrdDisplay;
  185.     property OutputFile: String read fOutputFile write fOutputFile;
  186.     property Password: String read fPassword write fPassword;
  187.     property PreventEscape: Boolean read fPreventEscape write fPreventEscape;
  188.     property PrinterName: String read fPrinterName write fPrinterName;
  189.     property PrinterPort: String read fPrinterPort write fPrinterPort;
  190.     property Replaces:Tstrings read fReplaces write SetfReplaces;
  191.     property ReportLibrary:String read fLibName write setLibName;
  192.     property ReportName: String read fRepName write setRepName;
  193.     property SortFields: TStrings read fSortFields write setfSortFields;
  194.     property StatusEveryPage: Boolean read fStatusEveryPage
  195.                                       write fStatusEveryPage;
  196.     property SuppressTitle: Boolean read fSuppressTitle write fSuppressTitle;
  197.     property TestPattern: Boolean read fTestPattern write fTestPattern;
  198.     property UserName: String read fUserName write fUserName;
  199.     property UserParamsNames: TStrings read fUserParamsNames
  200.                                        write setfUserParamsNames;
  201.     property UserParamsValues: TStrings read fUserParamsValues
  202.                                        write setfUserParamsValues;
  203.     property Version:String read fVersion write fversion;
  204.     property Wait: Boolean read fWait write fWait;
  205.     property Where: String read fWhere write fWhere;
  206.     property WinBorderStyle:TrrwsBorderStyle read fWinBorderStyle
  207.              write fWinBorderStyle default rrwsSizable;
  208.     property WinControlBox: Boolean read fWinControlBox write fWinControlBox;
  209.     property WinHeight: Integer read fWinHeight write fWinHeight;
  210.     property WinLeft: Integer read fWinLeft write fWinLeft;
  211.     property WinMaxButton: Boolean read fWinMaxButton write fWinMaxButton default true;
  212.     property WinMinButton: Boolean read fWinMinButton write fWinMinButton default true;
  213.     property WinParentHandle: Integer read fWinParentHandle write fWinParentHandle;
  214.     property WinTitle: String read fWinTitle write fWinTitle;
  215.     property WinTop:Integer read fWinTop write fWinTop;
  216.     property WinWidth:Integer read fWinWidth write fWinWidth;
  217. end;
  218.  
  219. procedure Register;
  220.  
  221. implementation
  222.  
  223. { ************************************************************************** }
  224. constructor TRRSQL60.create(AOwner:Tcomponent);
  225. { ************************************************************************** }
  226. begin
  227.   inherited create(AOwner);
  228.  
  229.   fAppName:=application.EXEname;
  230.  
  231.   fFields:=TStringList.Create;
  232.   fJoinTableNames:=TStringList.Create;
  233.   fJoinAliasNames:=TStringList.Create;
  234.   fGroupFields:=TStringList.Create;
  235.   fSortFields:=TStringList.Create;
  236.   fUserParamsNames:=TStringList.Create;
  237.   fUserParamsValues:=TStringList.Create;
  238.   fReplaces:=TStringList.Create;
  239.  
  240.   fAuthor:='cbrooksbank@msn.com';
  241.   fVersion:='1.00';
  242.   fBeginPage:=1;
  243.   fEndPage:=999999;
  244.   fOutputDest:=rrdDisplay;
  245.   fCopies:=1;
  246.   fWinBorderStyle:=rrwsSizable;
  247.   fWinMaxButton:=true;
  248.   fWinMinButton:=true;
  249.   fWait:=true;
  250. end;
  251.  
  252. { ************************************************************************** }
  253. destructor TRRSQL60.Free;
  254. { ************************************************************************** }
  255. begin
  256.   fFields.Free;
  257.   fJoinTableNames.Free;
  258.   fJoinAliasNames.Free;
  259.   fGroupFields.Free;
  260.   fSortFields.Free;
  261.   fUserParamsNames.Free;
  262.   fUserParamsValues.Free;
  263.   fReplaces.free;
  264.   inherited Free;
  265. end;
  266.  
  267.  
  268. { ************************************************************************** }
  269. procedure Register;
  270. { ************************************************************************** }
  271. begin
  272.   RegisterComponents('SI', [TRRSQL60]);
  273. end;
  274.  
  275.  
  276. { ************************************************************************** }
  277. procedure TRRSQL60.setlibname(NewLibName:String);
  278. { ************************************************************************** }
  279. begin
  280.   flibname:=NewLibName;
  281.   loadreportinfo;
  282. end;
  283.  
  284. { ************************************************************************** }
  285. procedure TRRSQL60.LoadReportInfo;
  286. { ************************************************************************** }
  287. { When reportname or libname change load various information }
  288. { from the report. E.G. fields,sort-fields,group-fields,joins e.t.c.}
  289. var
  290.   hMyReport:Integer;
  291.   MyApp_,MyLib_,MyRep_: array[0..255] of char;
  292. begin
  293.  
  294.   if ((fRepName<>'') and (fLibName<>'')) then begin
  295.  
  296.     fFields.Clear;
  297.     fSortFields.Clear;
  298.     fJoinTableNames.Clear;
  299.     fJoinAliasNames.Clear;
  300.     fGroupFields.Clear;
  301.  
  302.     StrPCopy(MyApp_,application.EXEname);
  303.     StrPCopy(MyLib_,fLibName);
  304.     StrPCopy(MyRep_,fRepName);
  305.  
  306.     InitRunTimeInstance;
  307.     try
  308.       hMyReport:=ChooseReport(MyApp_,MyLib_,MyRep_,sizeof(MyRep_));
  309.       try
  310.         if hMyReport>0 then begin
  311.           LoadFields(hMyReport);
  312.           LoadGroupFields(hMyReport);
  313.           LoadSortFields(hMyReport);
  314.           LoadJoins(hMyReport);
  315.           LoadUserParams(hMyReport);
  316.           LoadReplaces(hMyReport);
  317.           if fRepName='' then fRepName:=StrPas(MyRep_);
  318.         end;
  319.       finally
  320.         EndReport(hMyReport);
  321.       end;
  322.     finally
  323.       EndRunTimeInstance;
  324.     end;
  325.   end;
  326.  
  327. end;
  328.  
  329.  
  330. { ************************************************************************** }
  331. procedure TRRSQL60.LoadUserParams(hReport:Integer);
  332. { ************************************************************************** }
  333. var
  334.   ParamName,ParamValue:Array[0..30] of char;
  335. begin
  336.   GetFirstUserParam(hReport,ParamName,Sizeof(ParamName),
  337.                     paramValue,sizeof(ParamValue));
  338.   fUserParamsNames.Add(StrPas(ParamName));
  339.   fUSerParamsValues.Add(StrPas(ParamValue));
  340.   while GetNextUserParam(hReport,ParamName,Sizeof(ParamName),
  341.                          ParamValue,sizeof(ParamValue)) do begin
  342.     fUserParamsNames.Add(StrPas(ParamName));
  343.     fUSerParamsValues.Add(StrPas(ParamValue));
  344.   end;
  345. end;
  346.  
  347. { ************************************************************************** }
  348. procedure TRRSQL60.LoadFields(hReport:Integer);
  349. { ************************************************************************** }
  350. var
  351.   FieldName:Array[0..30] of char;
  352. begin
  353.   GetFirstFieldName(hReport,FieldName,Sizeof(FieldName));
  354.   fFields.Add(StrPas(FieldName));
  355.   while GetNextFieldName(hReport,FieldName,Sizeof(FieldName)) do
  356.     fFields.Add(StrPas(FieldName));
  357. end;
  358.  
  359. { ************************************************************************** }
  360. procedure TRRSQL60.LoadGroupFields(hReport:Integer);
  361. { ************************************************************************** }
  362. var
  363.   GroupField:Array[0..30] of char;
  364. begin
  365.   GetFirstGroupField(hReport,GroupField,Sizeof(GroupField));
  366.   fGroupFields.Add(StrPas(GroupField));
  367.   while GetNextGroupField(hReport,GroupField,Sizeof(GroupField)) do
  368.     fGroupFields.Add(StrPas(GroupField));
  369. end;
  370.  
  371. { ************************************************************************** }
  372. procedure TRRSQL60.LoadSortFields(hReport:Integer);
  373. { ************************************************************************** }
  374. var
  375.   SortField:Array[0..30] of char;
  376. begin
  377.   GetFirstSortField(hReport,SortField,Sizeof(SortField));
  378.   fSortFields.Add(StrPas(SortField));
  379.   while GetNextSortField(hReport,SortField,Sizeof(SortField)) do
  380.     fSortFields.Add(StrPas(SortField));
  381. end;
  382.  
  383. { ************************************************************************** }
  384. procedure TRRSQL60.LoadJoins(hReport:Integer);
  385. { ************************************************************************** }
  386. var
  387.   JoinTableName,JoinAliasName:Array[0..50] of char;
  388. begin
  389.   GetFirstJoinInfo(hReport,JoinTableName,Sizeof(JoinTableName),
  390.                    JoinAliasName,sizeof(JoinAliasName));
  391.  
  392.   fJoinTableNames.Add(StrPas(JoinTableName));
  393.   fJoinAliasNames.Add(StrPas(JoinAliasName));
  394.  
  395.   while GetNextJoinInfo(hReport,JoinTableName,Sizeof(JoinTableName),
  396.                         JoinAliasName,sizeof(JoinAliasName)) do begin
  397.     fJoinTableNames.Add(StrPas(JoinTableName));
  398.     fJoinAliasNames.Add(StrPas(JoinAliasName));
  399.   end
  400. end;
  401.  
  402.  
  403. { ************************************************************************** }
  404. procedure TRRSQL60.SetRepName(NewRepName: String);
  405. { ************************************************************************** }
  406. begin
  407.   fRepName:=NewRepName;
  408.   LoadReportInfo;
  409. end;
  410.  
  411.  
  412. { ************************************************************************** }
  413. function TRRSQL60.Run:Boolean;
  414. { ************************************************************************** }
  415. begin
  416.   Result:=Execute;
  417. end;
  418.  
  419.  
  420. { ************************************************************************** }
  421. function TRRSQL60.Execute:Boolean;
  422. { ************************************************************************** }
  423. var
  424.   { Handle of report }
  425.   hReport: Integer;
  426.  
  427.   { Temp vars to hold Pchar versions of String properties }
  428.   Appname_,LibName_,RepName_,DataSource_,PrinterName_: array[0..255] of char;
  429.   PrinterPort_,PassWord_,UserName_: array[0..30] of char;
  430.   filter_: array[0..255] of char;
  431.   MasterTableName_,MemoName_,OutputFile_,WinTitle_: array[0..255] of char;
  432.   Tablename_,Databasename_,Where_:array[0..255] of char;
  433.  
  434.   { Flags returned after report was run }
  435.   ECode:Integer;
  436.   cmdshow: Integer;
  437.   PageCount:LongInt;
  438.   EMsg:array[0..255] of char;
  439.  
  440.   ErrorMess: String;
  441.   CharString:String;
  442.   SiField,SiField2:array[0..255] of char;
  443.  
  444.   i:Integer;
  445.  
  446. begin
  447.   {Run the report }
  448.   Result:=false;
  449.  
  450.   { Convert Pascal type strings to C++ strings as expected by DLL }
  451.   StrPCopy(Appname_,fAppname);
  452.   StrPCopy(DataSource_,fDataSource);
  453.   StrPCopy(Filter_,fFilter);
  454.   StrPCopy(Libname_,fLibName);
  455.   StrPCopy(MasterTableName_,fMasterTableName);
  456.   StrPCopy(MemoName_,fMemoName);
  457.   StrPCopy(OutputFile_,fOutputFile);
  458.   StrPCopy(Password_,fPassword);
  459.   StrPCopy(Printername_,fPrinterName);
  460.   StrPCopy(PrinterPort_,fPrinterPort);
  461.   StrPCopy(RepName_,fRepName);
  462.   StrPCopy(UserName_,fUserName);
  463.   StrPCopy(WinTitle_,fWinTitle);
  464.   StrPCopy(Databasename_,fDatabasename);
  465.   StrPCopy(Where_,fwhere);
  466.  
  467.   { Initialise RSREPORT.DLL and get a handle for the report }
  468.   InitRuntimeInstance;
  469.   try
  470.     if AskReport then
  471.       hReport:=ChooseReport(Appname_,LibName_,RepName_,sizeof(RepName_))
  472.     else
  473.       hReport:=chooseReport(AppName_,LibName_,RepName_,Sizeof(RepName_));
  474.  
  475.     try
  476.       { Pass all the propertys to RSREPORT.DLL }
  477.       SetBeginPage(hReport,fBeginPage);
  478.       SetCopies(hReport,fCopies);
  479.       SetDisplayErrors(hReport,fDisplayErrors);
  480.       SetDisplayStatus(hReport,FDisplayStatus);
  481.       SetEndPage(hReport,fEndPage);
  482.  
  483.       CharString:=Copy('DFP',Ord(fExportDest)+1,1);
  484.       SetExportDest(hReport,CharString[1]);
  485.  
  486.       SetFilter(hReport,Filter_);
  487.  
  488.       CharString:=Copy('SEO?',Ord(fFilterUsage)+1,1);
  489.       SetFilterUsage(hReport,CharString[1]);
  490.  
  491.       SetMasterTableName(hReport,MasterTableName_);
  492.       SetMemoName(hReport,MemoName_);
  493.  
  494.       CharString:=Copy('DAPWX?',Ord(fOutputDest)+1,1);
  495.       SetOutputDest(hReport,CharString[1]);
  496.  
  497.       SetOutPutFile(hReport,OutputFile_);
  498.       SetPassword(hReport,Password_);
  499.       SetPreventEscape(hReport,fPreventEscape);
  500.       SetStatusEveryPage(hReport,fStatusEveryPage);
  501.       SetTestPattern(hReport,fTestPattern);
  502.       SetUserName(hReport,Username_);
  503.  
  504.       CharString:=Copy('0123',Ord(fWinBorderStyle)+1,1);
  505.       SetWinBorderStyle(hReport,Ord(CharString[1])-Ord('0'));
  506.  
  507.       SetWinControlBox(hReport,fWinControlBox);
  508.       SetWinHeight(hReport,fWinHeight);
  509.       SetWinLeft(hReport,fWinLeft);
  510.       SetWinMaxButton(hReport,fWinMaxButton);
  511.       SetWinMinButton(hReport,fWinMinButton);
  512.       SetWinParentHandle(hReport,fWinParentHandle);
  513.       SetWinTitle(hReport,WinTitle_);
  514.       SetWinTop(hReport,fWinTop);
  515.       SetWinWidth(hReport,fWinWidth);
  516.  
  517.       { Set sort fields }
  518.       for i:=0 to (fSortFields.Count-1) do begin
  519.         if ((fSortFields[i]<>'') and
  520.            (Pos('RECNO',UpperCase(fSortFields[i]))=0)) then begin
  521.           StrPCopy(SiField,fSortFields[i]);
  522.           SetSortField(hReport,SiField,i+1);
  523.         end;
  524.       end;
  525.  
  526.       { Set Group Fields }
  527.       for i:=0 to (fGroupFields.Count-1) do begin
  528.         if fGroupFields[i]<>'' then begin
  529.           StrPCopy(SiField,fGroupFields[i]);
  530.           SetGroupField(hReport,SiField,i+1);
  531.         end;
  532.       end;
  533.  
  534.       { Set join information }
  535.       for i:=0 to (fJoinTableNames.Count-1) do begin
  536.         if fJoinTableNames[i]<>'' then begin
  537.           StrPCopy(SiField,fJoinTableNames[i]);
  538.           StrPCopy(SiField2,fJoinAliasNames[i]);
  539.           SetJoinInfo(hReport,SiField,Sifield2,i+1);
  540.         end;
  541.       end;
  542.  
  543.       { Set user paramaters }
  544.       for i:=0 to (fUserParamsNames.Count-1) do begin
  545.         if fUserParamsNames[i]<>'' then begin
  546.           StrPCopy(SiField,fUserParamsNames[i]);
  547.           StrPCopy(SiField2,fUserParamsValues[i]);
  548.           SetUserParam(hreport,SiField,SiField2);
  549.         end;
  550.       end;
  551.  
  552.  
  553.       if AskPrinter then
  554.         choosePrinter(hReport,PrinterName_,sizeof(PrinterName_),
  555.                       PrinterPort_,sizeof(PrinterPort_));
  556.       SetPrinter(hReport,PrinterName_);
  557.       SetPrinterPort(hReport,PrinterPort_);
  558.  
  559.       if AskDataSource then
  560.         ChooseDataSource(hReport,Datasource_,sizeof(Datasource_));
  561.  
  562.  
  563.       if AskTable then ChooseTable(hReport,Tablename_,sizeof(TableName_),
  564.                                    DataSource_,sizeof(DataSource_),
  565.                                    Databasename_,sizeof(Databasename_));
  566.  
  567.       SetDataSource(hReport,DataSource_);
  568.  
  569.       if fwhere<>'' then SetWhere(hReport,where_);
  570.  
  571.       SaveReplaces(hReport);
  572.  
  573.       { Run the report and then clean up }
  574.       cmdshow:=SW_SHOWNORMAL;
  575.       fErrorCode:='';
  576.       fErrorMessage:='';
  577.       ResetErrorInfo;
  578.       if ExecRunTime(hReport,fWait,cmdshow,@ECode,@PageCount,EMsg,sizeof(EMsg))
  579.       then Result:=True else begin
  580.         geterrorinfo(Emsg,sizeof(EMsg),@Ecode);
  581.         fErrorMessage:=StrPas(EMsg);
  582.  
  583.         case Ecode of
  584.           Ord('C'):fErrorCode:='Cancelled';
  585.           Ord('D'):fErrorCode:='Diagnostic';
  586.           Ord('I'):fErrorCode:='Iteration';
  587.           Ord('J'):fErrorCode:='Job Control';
  588.           Ord('L'):fErrorCode:='Library';
  589.           Ord('S'):fErrorCode:='Syntax';
  590.           Ord('V'):fErrorCode:='Value';
  591.           else
  592.             fErrorCode:=Chr(Ecode);
  593.         end;
  594.  
  595.         MessageDlg('R&&R Error : '+StrPas(EMsg),mtError,[mbAbort],0);
  596.       end;
  597.     finally
  598.       EndReport(hReport);
  599.     end;
  600.   finally
  601.     endRunTimeInstance;
  602.   end;
  603. end;
  604.  
  605. { ************************************************************************** }
  606. procedure TRRSQL60.SetfFields(Value:Tstrings);
  607. { ************************************************************************** }
  608. begin
  609.   fFields.Assign(Value);
  610. end;
  611.  
  612. { ************************************************************************** }
  613. procedure TRRSQL60.SetfGroupFields(Value:Tstrings);
  614. { ************************************************************************** }
  615. begin
  616.   fGroupFields.Assign(Value);
  617. end;
  618.  
  619. { ************************************************************************** }
  620. procedure TRRSQL60.SetfJoinTableNames(Value:Tstrings);
  621. { ************************************************************************** }
  622. begin
  623.   fJoinTableNames.Assign(Value);
  624. end;
  625.  
  626. { ************************************************************************** }
  627. procedure TRRSQL60.SetfJoinAliasNames(Value:Tstrings);
  628. { ************************************************************************** }
  629. begin
  630.   fJoinAliasNames.Assign(Value);
  631. end;
  632.  
  633. { ************************************************************************** }
  634. procedure TRRSQL60.SetfReplaces(Value:Tstrings);
  635. { ************************************************************************** }
  636. begin
  637.   fReplaces.Assign(Value);
  638. end;
  639.  
  640. { ************************************************************************** }
  641. procedure TRRSQL60.SetfSortFields(Value:Tstrings);
  642. { ************************************************************************** }
  643. begin
  644.   fSortFields.Assign(Value);
  645. end;
  646.  
  647. { ************************************************************************** }
  648. procedure TRRSQL60.SetfUserParamsNames(Value:Tstrings);
  649. { ************************************************************************** }
  650. begin
  651.   fUserParamsNames.Assign(Value);
  652. end;
  653.  
  654. { ************************************************************************** }
  655. procedure TRRSQL60.SetfUserParamsValues(Value:Tstrings);
  656. { ************************************************************************** }
  657. begin
  658.   fUserParamsValues.Assign(Value);
  659. end;
  660.  
  661.  
  662. { ************************************************************************** }
  663. procedure TRRSQL60.SetfActive(Value:Boolean);
  664. { ************************************************************************** }
  665. begin
  666.   fActive:=Value;
  667.   if (not value) then
  668.     fActive:=Value else fActive:=execute;
  669. end;
  670.  
  671. { ************************************************************************** }
  672. procedure TRRSQL60.SetfAuthor(Value:String);
  673. { ************************************************************************** }
  674. begin
  675.   if Value<>'cbrooksbank@msn.com' then
  676.   messagedlg('Please send bugs/comments/enhancements to cbrooksbank@msn.com',mtInformation,
  677.               [mbOk],0);
  678.   fAuthor:='cbrooksbank@msn.com';
  679. end;
  680.  
  681. { ************************************************************************** }
  682. procedure TRRSQL60.SaveReplaces(hReport:Integer);
  683. { ************************************************************************** }
  684. var
  685.   i:Integer;
  686.   ThisReplace,ReplaceList:String;
  687.   Replaces_:array[0..255] of char;
  688. begin
  689.   ReplaceList:='';
  690.   for i:=0 to (fReplaces.count-1) do begin
  691.     ThisReplace:=fReplaces[i];
  692.     if ThisReplace<>'' then begin
  693.       ReplaceList:=ReplaceList+','+ThisReplace;
  694.     end;
  695.   end;
  696.  
  697.   if ReplaceList<>'' then begin
  698.     ReplaceList:=Copy(ReplaceList,1,length(replacelist)-1);
  699.     StrPCopy(Replaces_,ReplaceList);
  700.     SetReplace(hReport,Replaces_);
  701.   end;
  702. end;
  703.  
  704. { ************************************************************************** }
  705. procedure TRRSQL60.LoadReplaces(hReport:Integer);
  706. { ************************************************************************** }
  707. var
  708.   Replace:Array[0..30] of char;
  709. begin
  710.   GetFirstReplace(hReport,Replace,Sizeof(Replace));
  711.   fReplaces.Add(StrPas(Replace));
  712.   while GetNextReplace(hReport,Replace,Sizeof(Replace)) do
  713.     fReplaces.Add(StrPas(Replace));
  714. end;
  715. end.
  716.